package com.xinlu.user.action;

import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;

import com.xinlu.common.game.bo.ConstantLstBo;
import com.xinlu.derek.common.BaseAction;
import com.xinlu.derek.common.BaseForm;
import com.xinlu.persistence.Users;
import com.xinlu.user.bo.UsersBo;
import com.xinlu.user.form.HyglForm;
import com.xinlu.util.tool.DateUtil;

public class HyglAction extends BaseAction {

	HyglForm fr = new HyglForm();

	private UsersBo usersBo;

	public void setFr(HyglForm fr) {
		this.fr = fr;
	}

	public void setUsersBo(UsersBo usersBo) {
		this.usersBo = usersBo;
	}

	@Override
	public String doExecute() throws Exception {
		return null;
	}

	@Override
	public void formInit() {

	}

	@Override
	public BaseForm getModel() {

		// TODO 暂时方法 从增加会员、会员编辑页面反转到会员管理
		if ("zjhy".equals(fr.getPageId()) || "hybj".equals(fr.getPageId()) || "gxjcz".equals(fr.getPageId())) {
			fr.setPageId("hygl");
			fr.setDoAction("loadPage");
		}
		return fr;
	}

	/**
	 * 加载页面
	 * 
	 * @return
	 */
	public String loadPage() {
		Users users = (Users) getSession().getAttribute("userinfo");
		if (ConstantLstBo.isNullOrEmpty(fr.getCrtYhm())) {
			fr.setCrtYhm(users.getUsername());
		}

		fr.setYhzs(ConstantLstBo.getyhzs());
		fr.setYhz("--全部--");
		Date date = new Date();
		fr.setPageObject(usersBo.loadMembers(fr.getCrtYhm(), fr.getYhm(), fr.getYhz(), fr.getBgnYe(), fr.getEndYe(),fr.getPn()));

		fr.setControl(users.getControl());
		
		return "hygl";
	}

	/**
	 * 加载会员
	 * 
	 * @return
	 */
	public String loadMembers() {

		if (ConstantLstBo.isNullOrEmpty(fr.getCrtYhm())) {
			Users users = (Users) getSession().getAttribute("userinfo");
			fr.setCrtYhm(users.getUsername());
		}

		fr.setYhzs(ConstantLstBo.getyhzs());
		fr.setPageObject(usersBo.loadMembers(fr.getCrtYhm(), fr.getYhm(), fr.getYhz(), fr.getBgnYe(), fr.getEndYe(),fr.getPn()));

		return "hygl";
	}

	/**
	 * 冻结
	 * @return
	 */
	public String dongJie() {
		
		Users xjyh = usersBo.loadUser(fr.getXjYhm());
		xjyh.setLock(1);
		usersBo.update(xjyh);

		return loadPage();
	}

	/**
	 * 解冻
	 * @return
	 */
	public String jieDong() {

		Users xjyh = usersBo.loadUser(fr.getXjYhm());
		xjyh.setLock(0);
		usersBo.update(xjyh);
		
		return loadPage();
	}
}
